//
//  YHBaseView.m
//  MoreCoin
//
//  Created by 林宁宁 on 2019/9/17.
//  Copyright © 2019 MoreCoin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "YHBaseView.h"

@implementation YHBaseView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
         [self yh_commonInit];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if(self){
         [self yh_commonInit];
    }
    return self;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self yh_nibConfig];
}

- (void)yh_commonInit{};
- (void)yh_nibConfig{};


- (UIViewController *)viewController {
    //下一个响应者
    UIResponder *next = [self nextResponder];
    do {
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        next = [next nextResponder];
    } while (next);
    return nil;
}

+ (instancetype)initFromNib{
    
    NSString *nibName = NSStringFromClass([self class]);
    if ([nibName containsString:@"."]){
        NSArray *array = [nibName componentsSeparatedByString:@"."];
        nibName = [array lastObject];
    }
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:nibName owner:nil
                                                 options:nil];
    return [array firstObject];
}

-(void)dealloc{
    NSLog(@"=======dealloc======:%@",NSStringFromClass([self class]));
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
